<<<<<<< HEAD
const config = require('../config/config')

exports.createPool = function () {
    const mysql = require('mysql');
    global.pool = mysql.createPool(config.mysql);
=======
exports.createPool = function () {
    const mysql = require('mysql');
    global.pool = mysql.createPool({
        host: '42.123.121.227',
        user: 'root',
        password: 'root@1234',
        database: 'guian',
        port: 3306,
        allowMultiQueries: true
    });
>>>>>>> f39b58d3ecd4b966b4fad479559750bf2f0d0858
}


exports.db = function () {
    this.getAll = function (sql, cb) {
        poolQuery(sql, (err, data) => {
            cb && cb(err, data)
        })
    }
}


function poolQuery(sql, callback) {
    global.pool.getConnection((error, conn) => {
        error ? console("pool error!") :
            conn.query(sql, function (err, rows) {
                callback && callback(err, rows);
                conn.release();
            });
    });
}